<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            name: '对象name',
            sayHello: function () {
                console.log('打印对象方法', this.name)
                return this.name
            },

        }
        let method_Name = 'm'
        let symbol = Symbol()
        let testObj = {
            "method with Spaces"(x) {
                return x
            },
            [method_Name](x) {
                return x
            },
            [symbol](x) {
                return x
            }
        }

        console.log(
            testObj["method with Spaces"](1),
            testObj[method_Name](2),
            testObj[symbol](3)
        )

        let points = [{ x: 10, y: 20 }, { x: 20, y: 10 }]
        // 给数组添加方法，不会影像数组的长度
        points.dist = function () {
            let p1 = this[0]
            let p2 = this[1]
            let a = p2.x - p1.x
            let b = p2.y - p1.y
            return Math.sqrt(a * a + b * b)
        }
        console.log('两点之间距离:',points,points.length,
        points.dist())
    </script>
</body>

</html>